package com.formula.datastructure.question.vector;

import com.formula.datastructure.standard.vector.Vector;
import com.formula.datastructure.standard.vector.DataNode;

public class W_18_1 {

    // #1
    public DataNode deleteMin(Vector vector) throws Exception {
        if (vector.size() == 0) {
            throw new Exception("Vector is empty");
        }
        DataNode[] nodes = vector.getVector();
        DataNode min = nodes[0];
        int index = 0;
        for (int i = 1; i < vector.size(); i++) {
            if (nodes[i].data < min.data) {
                min = nodes[i];
                index = i;
            }
        }
        vector.deleteByIndex(index);
        return min;
    }

    // #2
    public DataNode[] reverse(Vector vector) {
        DataNode[] nodes = vector.getVector();
        int size = vector.size();
        int half = size / 2;
        Integer temp;
        for (int i = 0; i < half; i++) {
            temp = nodes[i].data;
            nodes[i].data = nodes[size - 1 - i].data;
            nodes[size - 1 - i].data = temp;
        }
        return nodes;
    }

    // #12
    public Integer getMainElem(Vector vector) {
        Integer result = null;
        DataNode[] nodes = vector.getVector();

        return result;
    }

    public static void main(String[] args) {
    }
}
